import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/img_verification";

export const get_pic_uuid_api = (showError = true) => {
  return Http.get<{ uuid: string }>(`/v1${baseUrl}/get_pic_uuid`).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const verification_api = (
  data: { uuid: string; value: number },
  showError = true
) => {
  return Http.get<{ sms_id: string }>(`/v1${baseUrl}/verification`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const send_code_api = (
  data: {
    sms_id: string;
    telephone: string;
    send_type: number;
    secret: string;
  },
  showError = true
) => {
  return Http.post(`/v1${baseUrl}/send_code`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
